package org.blogsomy.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.code.lightsomy.annotations.Action;
import com.google.code.lightsomy.annotations.BeforeAction;
import com.google.code.lightsomy.annotations.Controller;
import com.google.code.lightsomy.output.Renderer;

@Controller
public class AuthController {

	private Renderer velocity;
	
	@BeforeAction
	public void prepare(HttpServletRequest req, HttpServletResponse res) {
		velocity = Renderer.getRenderer(Renderer.Type.VELOCITY, req, res);
	}
	
	@Action
	public void login(HttpServletRequest req, HttpServletResponse res) throws IOException {
		velocity.output(velocity.render());
	}
	
	@Action
	public void logout(HttpServletRequest req, HttpServletResponse res) throws IOException {
		req.getSession(false).invalidate();
		res.sendRedirect(req.getParameter("root"));
	}
	
	@Action
	public void error(HttpServletRequest req, HttpServletResponse res) throws IOException {
		velocity.output(velocity.render());
	}
}
